package com.bd.scm.module.jurisdiction.controller;

import com.bd.scm.domain.models.jurisdiction.BdSysLoginUser;
import com.bd.scm.domain.models.jurisdiction.BdSysMenu;
import com.bd.scm.module.jurisdiction.service.BdSysMenuService;
import com.bd.utils.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/** 菜单逻辑
 * @author YH
 * @version 1.0
 * @date 2020/12/15 10:06
 */
@RestController
@RequestMapping("api/bdSysMenu")
public class BdSysMenuController {

    @Autowired
    private BdSysMenuService bdSysMenuService;

    /**
     * 菜单添加 修改
     * @param bdSysMenu
     * @return
     */
    @PostMapping("savaMenu")
    public Result savaMenu(@RequestBody BdSysMenu bdSysMenu){
        Result result = null;
        try {
            //添加
            if(bdSysMenu.getId()==null){
                this.bdSysMenuService.addMenu(bdSysMenu);
            }else{
                //修改
                this.bdSysMenuService.updateMenu(bdSysMenu);
            }
            result = Result.ok("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("服务器内部错误，保存失败");
        }
        return result;
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @GetMapping("deleteMenu")
    public Result deleteMenu(@RequestBody int[] ids){
        Result result = null;
        try {
            this.bdSysMenuService.deleteMenu(ids);
            result = Result.ok("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("服务器内部错误，删除失败");
        }
        return result;
    }

}
